package com.niit.service.impl;

import java.util.List;

import com.niit.bean.Blog;
import com.niit.dao.BlogDao;
import com.niit.dao.impl.BlogDaoImpl;
import com.niit.service.BlogService;
import com.niit.utils.Page;

public class BlogServiceImpl implements BlogService {
	
	private BlogDao dao = new BlogDaoImpl();
	@Override
	public int add(Blog t) {
		return dao.add(t);
	}

	@Override
	public int delete(Blog t) {
		return dao.delete(t);
	}

	@Override
	public int update(Blog t) {
		return dao.update(t);
	}

	@Override
	public Page<Blog> getPage(String pagenum, String url) {
		int total = dao.findTotal();
		Page<Blog> page = null;
		if(pagenum == null){
			page = new Page<Blog>(total,1);
		}else{
			page = new Page<Blog>(total, Integer.parseInt(pagenum));
		}
		List<Blog> list = dao.findAll(page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}
	@Override
	public Blog findByBlogId(String blogId) {
		return dao.findByBlogId(blogId);
	}

}
